<?php

/* 
 * 
 * 
 * 
 */

class hotelapi extends actionAbstract{
    //构造函数
	function __construct() {
		parent::__construct ();
		set_time_limit ( 0 );
	}
	
    /**
     * 权限MD5加密
     */
    function SignUtil(){
        global $myconfigs;
        $agentid = $myconfigs['agentid'];
        $key = $myconfigs['key'];
        $sign = md5(md5($agentid.$key));
        $arr = array();
        $arr['agenid'] = $agentid;
        $arr['sign'] = $sign;
        return $arr;
    }
    
    /**
     * curl 传输
     */
    function curl($action,$params=null,$url="http://open.qmango.com/hotel/"){
        if(!$action){return "服务名错误！";}
        global $myconfigs;
        $agentid = $myconfigs['agentid'];
        $key = $myconfigs['key'];
        
        $sign = $this->SignUtil();
        $get = '';
        
        if($action == 'getorderprice'){
			$params['agentid']=$agentid;
			ksort($params);
			$psm="";
			foreach($params as $k=>$v){
				$psm.="&".$k."=".$v;
			}
			$psm=trim($psm,'&');
			$sign=md5($psm.$key);
			$curl=$url.$action."?".$psm."&sign=".$sign;
			//echo '<pre>';print_r($params);exit;
        }else if($action == 'booking'){
            $curl = $url.$action;
        }else{
            if($params){
                $get = '&';
                foreach($params as $key => $value){
                    $get .= $key.'='.$value."&";
                }
                $get = substr($get,0,strlen($get)-1);
            }
            $curl = $url.$action."?agentid=".$sign['agenid']."&sign=".$sign['sign'].$get;
        }
        
        //初始化
        $ch = curl_init();
        //设置选项，包括URL
        curl_setopt($ch, CURLOPT_URL, $curl);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        if($action == 'booking'){
            //POST请求
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
        }else{
            //GET请求
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt ( $ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json; charset=utf-8"));
        }
        $return = curl_exec ( $ch );
		$logs="调用地址：".$curl."\r\n接收数据：".$return."\r\n发送数据：".$get;
        $this->setLogs($logs,$path="/data/Logs/hotelapi/");
        //释放curl句柄
        curl_close($ch);
		
        $data = simplexml_load_string($return);
        if($action == 'detail'){
            $data->hotel->intro = @trim(@trim($data->hotel->intro,'<![CDATA['),']]>');
            $data->hotel->htips = @trim(@trim($data->hotel->htips,'<![CDATA['),']]>');
            $data->hotel->address = @trim(@trim($data->hotel->address,'<![CDATA['),']]>');
            $data->hotel->ad = @trim(@trim($data->hotel->ad,'<![CDATA['),']]>');
            $data->hotel->roomName = @trim(@trim($data->hotel->roomName,'<![CDATA['),']]>');
            $data->hotel->jiaotong = @trim(@trim($data->hotel->jiaotong,'<![CDATA['),']]>');
        }else if($action == 'room'){
			if(is_object($data->list->room)){
				foreach($data->list->room as $list_key => $list_value){
					@$list_value->content = @trim(@trim($list_value,'<![CDATA['),']]>');
				}
			}
        }else if($action == 'comment'){
			if(is_object($data->list->comment)){
				foreach($data->list->comment as $list_key => $list_value){
					@$list_value->content = @trim(@trim($list_value->content,'<![CDATA['),']]>');
				}
			}
        }else if($action == 'traffic'){
			if(is_object($data->list->traffic)){
				foreach($data->list->traffic as $list_key => $list_value){
					@$list_value->content = @trim(@trim($list_value->content,'<![CDATA['),']]>');
				}
			}
        }
        $xml = @json_decode(@json_encode($data),TRUE);
        //echo "<pre>";print_r($xml);exit;
        if($xml){
            if(isset($xml['status'])&&$xml['status']==1){return $xml;}
            return "数据错误，请联系技术人员！";
        }
        return "获取内容失败！";
    }
	
	//酒店 数组 字符串
	function nowHotel(){
		$this->loadModel('qm','hotel');
		
		$sql="select hid from qm_hotel where id>3072";//>3072
		$re=$this->qm->hotelModel->fetchAll($sql);
		
		$in="";//酒店字符串
		foreach($re as $k=>$v){$in.="'".$v['hid']."',";}
		$in=trim($in,",");
		
		return $in;
	}
	
    //获取酒店详情
    function getHotelDetails(){
		$this->loadModel('qm','hotel');
		$this->loadModel('tc','province');
		$this->loadModel('tc','city');
		$this->loadModel('tc','county');
		$in=$this->nowHotel();
		$hotels = $this->qm->hotelModel->fetchAll("select hid from qm_hotel where hid in (".$in.")");
		$areOk=0;
		if($hotels){
			foreach ($hotels as $k => $v){
				$data=array();
				$re=$this->curl('detail',array('hotelid' => $v['hid']));
				if($re&&is_array($re)&&!empty($re['hotel']['@attributes']['name'])){
					$pr=$this->tc->provinceModel->fetchRow("select osiiid,name from tc_province where name='".@$re['hotel']['@attributes']['provinceName']."'");
					if($pr){
						$data['osiiProvinceID'] = $pr['osiiid'];
						$data['osiiProvinceName'] = $pr['name'];
						
						$cityName='';
						if(strstr($re['hotel']['@attributes']['cityName'],'市')||strstr($re['hotel']['@attributes']['cityName'],'区')){
							$cityName=mb_substr($re['hotel']['@attributes']['cityName'],0,-1,'utf-8');
						}else{$cityName=$re['hotel']['@attributes']['cityName'];}
						$cityName=$cityName?$cityName:'';
						$ci=$this->tc->cityModel->fetchRow("select osiiid,name from tc_city where province_id=".$data['osiiProvinceID']." and name like '".$cityName."%'");
						if($ci){
							$data['osiiCityID']=$ci['osiiid'];
							$data['osiiCityName']=$ci['name'];
						}else{
							$cit=$this->tc->cityModel->fetchRow("select osiiid,name from tc_city where province_id=".$data['osiiProvinceID']);
							$data['osiiCityID']=$cit['osiiid'];
							$data['osiiCityName']=$cit['name'];
						}
						
						$areaName='';
						if(strstr($re['hotel']['@attributes']['areaName'],'市')||strstr($re['hotel']['@attributes']['areaName'],'区')||strstr($re['hotel']['@attributes']['areaName'],'县')){
							$areaName=mb_substr($re['hotel']['@attributes']['areaName'],0,-1,'utf-8');
						}else{$areaName=$re['hotel']['@attributes']['areaName'];}
						$areaName=$areaName?$areaName:'';
						$cu=$this->tc->countyModel->fetchRow("select osiiid,name from tc_county where city_id=".$data['osiiCityID']." and name like '".$areaName."%'");
						if($cu){
							$data['osiiCountyID']=$cu['osiiid'];
							$data['osiiCountyName']=$cu['name'];
						}else{
							$cut=$this->tc->countyModel->fetchRow("select osiiid,name from tc_county where city_id=".$data['osiiCityID']);
							$data['osiiCountyID']=$cut['osiiid'];
							$data['osiiCountyName']=$cut['name'];
						}
					}
					
					$data['name'] = !empty($re['hotel']['@attributes']['name'])?$re['hotel']['@attributes']['name']:'';
                    $data['provinceName'] = !empty($re['hotel']['@attributes']['provinceName'])?$re['hotel']['@attributes']['provinceName']:'';
                    $data['cityName'] = !empty($re['hotel']['@attributes']['cityName'])?$re['hotel']['@attributes']['cityName']:'';
                    $data['areaName'] = !empty($re['hotel']['@attributes']['areaName'])?$re['hotel']['@attributes']['areaName']:'';
                    $data['provinceId'] = !empty($re['hotel']['@attributes']['provinceId'])?$re['hotel']['@attributes']['provinceId']:0;
                    $data['cityId'] = !empty($re['hotel']['@attributes']['cityId'])?$re['hotel']['@attributes']['cityId']:0;
                    $data['coord'] = !empty($re['hotel']['@attributes']['coord'])?$re['hotel']['@attributes']['coord']:'';
                    $data['resourceid'] = !empty($re['hotel']['@attributes']['resourceid'])?$re['hotel']['@attributes']['resourceid']:0;
                    $data['tag'] = !empty($re['hotel']['tag'])?$re['hotel']['tag']:'';
                    $data['intro'] = !empty($re['hotel']['intro'])?$re['hotel']['intro']:'';
                    $data['htips'] = !empty($re['hotel']['htips'])?$re['hotel']['htips']:'';
                    $data['address'] = !empty($re['hotel']['address'])?$re['hotel']['address']:'';
                    $data['ad'] = !empty($re['hotel']['ad'])?$re['hotel']['ad']:'';
                    $data['type'] = !empty($re['hotel']['type'])?$re['hotel']['type']:'';
                    $data['tjgrade'] = !empty($re['hotel']['tjgrade'])?$re['hotel']['tjgrade']:'';
                    $data['tjgradenum'] = !empty($re['hotel']['tjgradenum'])?$re['hotel']['tjgradenum']:0;
                    $data['logoPic'] = !empty($re['hotel']['logoPic'])?$re['hotel']['logoPic']:'';
                    $data['roomName'] = !empty($re['hotel']['roomName'])?$re['hotel']['roomName']:'';
                    $data['roomPrice'] = !empty($re['hotel']['roomPrice'])?$re['hotel']['roomPrice']:0;
                    $data['jiaotong'] = !empty($re['hotel']['jiaotong'])?$re['hotel']['jiaotong']:'';
                    $data['tqydts'] = !empty($re['hotel']['tqydts'])?$re['hotel']['tqydts']:0;
                    $data['lastArrTime'] = !empty($re['hotel']['lastArrTime'])?$re['hotel']['lastArrTime']:0;
                    $data['avgcomment'] = !empty($re['hotel']['avgcomment'])?$re['hotel']['avgcomment']:0;
                    $data['tell'] = !empty($re['hotel']['@attributes']['tel'])?$re['hotel']['@attributes']['tel']:'';
                    $data['created'] = date('Y-m-d H:i:s',time());
					$rest=$this->qm->hotelModel->update($data,"hid=".$v['hid']);
					if($rest){$areOk+=1;}
				}
			}
			exit(json_encode(array('state'=>1,'html'=>"更新了 ".$areOk." 个酒店！")));
		}
		exit(json_encode(array('state'=>0,'html'=>"暂无酒店ID可获取！")));
    }
    
    //获取酒店房型
    function getHotelRoom(){
        $this->loadModel('qm','room');
        $this->loadModel('qm','hotel');
		$hid = isset($_POST['hid'])?(int)($_POST['hid']):0;
		$j=0;
		if($hid){
			$re=$this->curl('room',array('hotelid' => $hid));
			if($re&&is_array($re)&&!empty($re['list']['room'])){
				foreach($re['list']['room'] as $k=>$v){
					if(!empty($v['@attributes']['id'])){
						$data['hid'] = $hid;
						$data['rid'] = !empty($v['@attributes']['id'])?$v['@attributes']['id']:0;
						$data['name'] = !empty($v['@attributes']['name'])?$v['@attributes']['name']:'';
						$data['breakfast'] = !empty($v['@attributes']['breakfast'])?$v['@attributes']['breakfast']:'';
						$data['bathroom'] = !empty($v['@attributes']['bathroom'])?$v['@attributes']['bathroom']:'';
						$data['hasTV'] = !empty($v['@attributes']['hasTV'])?trim($v['@attributes']['hasTV']):'';
						$data['hasTel'] = !empty($v['@attributes']['hasTel'])?trim($v['@attributes']['hasTel']):'';
						$data['kongtiao'] = !empty($v['@attributes']['kongtiao'])?trim($v['@attributes']['kongtiao']):'';
						$data['internet'] = !empty($v['@attributes']['internet'])?trim($v['@attributes']['internet']):'';
						$data['maxNum'] = !empty($v['@attributes']['maxNum'])?$v['@attributes']['maxNum']:0;
						$data['price'] = !empty($v['@attributes']['price'])?$v['@attributes']['price']:0;
						$data['roomStatus'] = !empty($v['@attributes']['roomStatus'])?$v['@attributes']['roomStatus']:0;
						$data['bePrepay'] = !empty($v['@attributes']['bePrepay'])?$v['@attributes']['bePrepay']:0;
						$data['redFree'] = !empty($v['@attributes']['redFree'])?$v['@attributes']['redFree']:0;
						$data['commentFree'] = !empty($v['@attributes']['commentFree'])?$v['@attributes']['commentFree']:0;
						$data['commission'] = !empty($v['@attributes']['commission'])?$v['@attributes']['commission']:0;
						$data['isshared'] = !empty($v['@attributes']['isshared'])?$v['@attributes']['isshared']:'';
						$data['content'] = !empty($v['content'])?$v['content']:'';
						$data['created'] = date('Y-m-d H:i:s',time());
						$rq=$this->qm->roomModel->fetchRow("select id from qm_room where hid=$hid and rid=".$data['rid']);
						if($rq){$qs=$this->qm->roomModel->update($data,"id=".$rq['id']);}
						else{$qs=$this->qm->roomModel->insert($data);}
						if($qs){$j++;}
					}
				}
			}
		}else{
			$in=$this->nowHotel();
			$rst=$this->qm->hotelModel->fetchAll("select hid from qm_hotel where `name`!='' and osiiCityID>0 and osiiCountyID>0 and osiiProvinceID>0 and hid in (".$in.")");
			if($rst){
				foreach($rst as $k=>$v){
					$re=$this->curl('room',array('hotelid' => $v['hid']));
					if($re&&is_array($re)&&!empty($re['list']['room'])){
						foreach($re['list']['room'] as $ka=>$va){
							if(!empty($va['@attributes']['id'])){
								$data['hid'] = $v['hid'];
								$data['rid'] = !empty($va['@attributes']['id'])?$va['@attributes']['id']:0;
								$data['name'] = !empty($va['@attributes']['name'])?$va['@attributes']['name']:'';
								$data['breakfast'] = !empty($va['@attributes']['breakfast'])?$va['@attributes']['breakfast']:'';
								$data['bathroom'] = !empty($va['@attributes']['bathroom'])?$va['@attributes']['bathroom']:'';
								$data['hasTV'] = !empty($va['@attributes']['hasTV'])?trim($va['@attributes']['hasTV']):'';
								$data['hasTel'] = !empty($va['@attributes']['hasTel'])?trim($va['@attributes']['hasTel']):'';
								$data['kongtiao'] = !empty($va['@attributes']['kongtiao'])?trim($va['@attributes']['kongtiao']):'';
								$data['internet'] = !empty($va['@attributes']['internet'])?trim($va['@attributes']['internet']):'';
								$data['maxNum'] = !empty($va['@attributes']['maxNum'])?$va['@attributes']['maxNum']:0;
								$data['price'] = !empty($va['@attributes']['price'])?:0;
								$data['roomStatus'] = !empty($va['@attributes']['roomStatus'])?:0;
								$data['bePrepay'] = !empty($va['@attributes']['bePrepay'])?:0;
								$data['redFree'] = !empty($va['@attributes']['redFree'])?:0;
								$data['commentFree'] = !empty($va['@attributes']['commentFree'])?:0;
								$data['commission'] = !empty($va['@attributes']['commission'])?$va['@attributes']['commission']:0;
								$data['isshared'] = !empty($va['@attributes']['isshared'])?$va['@attributes']['isshared']:'';
								$data['content'] = !empty($va['content'])?$va['content']:'';
								$data['created'] = date('Y-m-d H:i:s',time());
								$rq=$this->qm->roomModel->fetchRow("select id from qm_room where hid=".$v['hid']." and rid=".$data['rid']);
								if($rq){$qs=$this->qm->roomModel->update($data,"id=".$rq['id']);}
								else{$qs=$this->qm->roomModel->insert($data);}
								if($qs){$j++;}
							}
						}
					}
				}
			}
		}
		exit(json_encode(array('state'=>1,'html'=>"更新了 ".$j." 个房型，请刷新后查看！")));
    }
    
	//获取酒店图片
    function getHotelImg(){
		$this->loadModel('qm', 'image');
        $this->loadModel('qm','hotel');
		$hid = isset($_POST['hid'])?(int)($_POST['hid']):0;
		$j=0;
		if($hid){
			$re=$this->curl('img',array('hotelid' => $hid,'pageIndex'=>1,'pageSize'=>1000));
			if($re&&is_array($re)&&!empty($re['list']['img'])){
				foreach($re['list']['img'] as $k=>$v){
					if(!empty($v['@attributes']['url'])){
						$data['hid'] = $hid;
						$data['title'] = !empty($v['@attributes']['title'])?$v['@attributes']['title']:'';
						$data['url'] = !empty($v['@attributes']['url'])?$v['@attributes']['url']:'';
						$data['surl'] = !empty($v['@attributes']['surl'])?$v['@attributes']['surl']:'';
						$data['created'] = date('Y-m-d H:i:s',time());
						$rq=$this->qm->imageModel->fetchRow("select id from qm_image where hid=$hid and url='".$v['@attributes']['url']."'");
						if($rq){$qs=$this->qm->imageModel->update($data,"id=".$rq['id']);}
						else{$qs=$this->qm->imageModel->insert($data);}
						if($qs){$j++;}
					}
				}
			}
		}else{
			$rst=$this->qm->hotelModel->fetchAll("select hid from qm_hotel where `name`!='' and osiiCityID>0 and osiiCountyID>0 and osiiProvinceID>0");
			if($rst){
				foreach($rst as $k=>$v){
					$re=$this->curl('img',array('hotelid' => $v['hid']));
					if($re&&is_array($re)&&!empty($re['list']['img'])){
						foreach($re['list']['img'] as $ka=>$va){
							if(!empty($va['@attributes']['url'])){
								$data['hid'] = $v['hid'];
								$data['title'] = !empty($va['@attributes']['title'])?$va['@attributes']['title']:'';
								$data['url'] = !empty($va['@attributes']['url'])?$va['@attributes']['url']:'';
								$data['surl'] = !empty($va['@attributes']['surl'])?$va['@attributes']['surl']:'';
								$data['created'] = date('Y-m-d H:i:s',time());
								$rq=$this->qm->imageModel->fetchRow("select id from qm_image where hid=$hid and url='".$va['@attributes']['url']."'");
								if($rq){$qs=$this->qm->imageModel->update($data,"id=".$rq['id']);}
								else{$qs=$this->qm->imageModel->insert($data);}
								if($qs){$j++;}
							}
						}
					}
				}
			}
		}
		exit(json_encode(array('state'=>1,'html'=>"更新了 ".$j." 个图片，请刷新后查看！")));
    }
	
    //获取房态
    function getHotelRoomBatch(){
		$this->loadModel('qm', 'room');
		$this->loadModel('qm', 'roombatch');
		//$hid = 53;
		//$rid = 290314;
		$hid = isset($_POST['hid'])?(int)($_POST['hid']):0;
		$rid = isset($_POST['rid'])?(int)($_POST['rid']):0;
		
		$in='';
		
		$j=0;
		if((!$hid&&!$rid)||($hid&&!$rid)){
			$where="";
			if($hid){$where=" where hid=$hid";}else{$where=" where hid in (".$in.")";}
			$count=$this->qm->roomModel->fetchRow("select count(id) as thcount from qm_room".$where);
			$count=$count['thcount'];
			if($count<=1000){
				$rst=$this->qm->roomModel->fetchAll("select hid,rid from qm_room".$where);
				foreach($rst as $k=>$v){
					$re=$this->curl('roombatch',array('hotelid'=>$v['hid'],'roomId'=>$v['rid'],'sdate'=>date('Y-m-d',time()+24*3600),'edate'=>date('Y-m-d',time()+32*24*3600)));
					if(!empty($re['list']['room']['roomDatelist'])){
						foreach($re['list']['room']['roomDatelist'] as $ka=>$va){
							$data['hid'] = $v['hid'];
							$data['rid'] = $v['rid'];
							$data['date'] = !empty($va['@attributes']['date'])?$va['@attributes']['date']:'';
							$data['price'] = !empty($va['@attributes']['price'])?$va['@attributes']['price']:0;
							$data['roomStatus'] = !empty($va['@attributes']['roomStatus'])?$va['@attributes']['roomStatus']:0;
							$data['maxNum'] = !empty($va['@attributes']['maxNum'])?$va['@attributes']['maxNum']:0;
							$data['paymentMode'] = !empty($va['@attributes']['paymentMode'])?$va['@attributes']['paymentMode']:0;
							$data['redFree'] = !empty($va['@attributes']['redFree'])?$va['@attributes']['redFree']:0;
							$data['commentFree'] = !empty($va['@attributes']['commentFree'])?$va['@attributes']['commentFree']:0;
							$data['breakfast'] = !empty($va['@attributes']['breakfast'])?$va['@attributes']['breakfast']:'不含早';
							$data['created'] = date('Y-m-d H:i:s',time());
							$rq=$this->qm->roombatchModel->fetchRow("select id from qm_roombatch where hid=".$v['hid']." and rid=".$v['rid']." and date='".@$va['@attributes']['date']."'");
							if($rq){$qs=$this->qm->roombatchModel->update($data,"id=".$rq['id']);}
							else{$qs=$this->qm->roombatchModel->insert($data);}
							if($qs){$j++;}
						}
					}
				}
			}else{
				$page=ceil($count/1000);
				for($i=0;$i<$page;$i++){
					$rst=$this->qm->roomModel->fetchAll("select hid,rid from qm_room".$where." limit ".($i*1000).",1000");
					foreach($rst as $k=>$v){
						$re=$this->curl('roombatch',array('hotelid'=>$v['hid'],'roomId'=>$v['rid'],'sdate'=>date('Y-m-d',time()+24*3600),'edate'=>date('Y-m-d',time()+32*24*3600)));
						if(!empty($re['list']['room']['roomDatelist'])){
							foreach($re['list']['room']['roomDatelist'] as $ka=>$va){
								$data['hid'] = $v['hid'];
								$data['rid'] = $v['rid'];
								$data['date'] = !empty($va['@attributes']['date'])?$va['@attributes']['date']:'';
								$data['price'] = !empty($va['@attributes']['price'])?$va['@attributes']['price']:0;
								$data['roomStatus'] = !empty($va['@attributes']['roomStatus'])?$va['@attributes']['roomStatus']:0;
								$data['maxNum'] = !empty($va['@attributes']['maxNum'])?$va['@attributes']['maxNum']:0;
								$data['paymentMode'] = !empty($va['@attributes']['paymentMode'])?$va['@attributes']['paymentMode']:0;
								$data['redFree'] = !empty($va['@attributes']['redFree'])?$va['@attributes']['redFree']:0;
								$data['commentFree'] = !empty($va['@attributes']['commentFree'])?$va['@attributes']['commentFree']:0;
								$data['breakfast'] = !empty($va['@attributes']['breakfast'])?$va['@attributes']['breakfast']:'不含早';
								$data['created'] = date('Y-m-d H:i:s',time());
								$rq=$this->qm->roombatchModel->fetchRow("select id from qm_roombatch where hid=".$v['hid']." and rid=".$v['rid']." and date='".@$va['@attributes']['date']."'");
								if($rq){$qs=$this->qm->roombatchModel->update($data,"id=".$rq['id']);}
								else{$qs=$this->qm->roombatchModel->insert($data);}
								if($qs){$j++;}
							}
						}
					}
				}
			}
		}elseif($hid&&$rid){
			$re=$this->curl('roombatch',array('hotelid'=>$hid,'roomId'=>$rid,'sdate'=>date('Y-m-d',time()+24*3600),'edate'=>date('Y-m-d',time()+30*24*3600)));
			if(!empty($re['list']['room']['roomDatelist'])){
				foreach($re['list']['room']['roomDatelist'] as $k=>$v){
					$data['hid'] = $hid;
                    $data['rid'] = $rid;
                    $data['date'] = !empty($v['@attributes']['date'])?$v['@attributes']['date']:'';
                    $data['price'] = !empty($v['@attributes']['price'])?$v['@attributes']['price']:0;
                    $data['roomStatus'] = !empty($v['@attributes']['roomStatus'])?$v['@attributes']['roomStatus']:0;
                    $data['maxNum'] = !empty($v['@attributes']['maxNum'])?$v['@attributes']['maxNum']:0;
                    $data['paymentMode'] = !empty($v['@attributes']['paymentMode'])?$v['@attributes']['paymentMode']:0;
                    $data['redFree'] = !empty($v['@attributes']['redFree'])?$v['@attributes']['redFree']:0;
                    $data['commentFree'] = !empty($v['@attributes']['commentFree'])?$v['@attributes']['commentFree']:0;
					$data['breakfast'] = !empty($va['@attributes']['breakfast'])?$va['@attributes']['breakfast']:'不含早';
                    $data['created'] = date('Y-m-d H:i:s',time());
					$rq=$this->qm->roombatchModel->fetchRow("select id from qm_roombatch where hid=$hid and rid=$rid and date='".@$v['@attributes']['date']."'");
					if($rq){$qs=$this->qm->roombatchModel->update($data,"id=".$rq['id']);}
					else{$qs=$this->qm->roombatchModel->insert($data);}
					if($qs){$j++;}
				}
			}
		}
		exit(json_encode(array('state'=>1,'html'=>"更新了 ".$j." 条房态，请刷新后查看！")));
    }
    
}